package com.taotao.thread.Test1;

import java.util.concurrent.*;

/**
 * @author wangjin
 * @title: Test1
 * @projectName thread
 * @description: 线程的创建方式，
 * @date 2022/5/3 0003 11:44
 */
public class Test1 extends Thread {
    private volatile int t;

    public static void main(String[] args) {
        Test1 test1 = new Test1();
        test1.start();
        new Thread1().start();
        Thread t = new Thread(new FutureTask<String>(new MyCall()));
         t.start();
         ExecutorService service= Executors.newCachedThreadPool();
         service.execute(()->{
             System.out.println("hello Threadpools");
        });
      //   service.shutdown();
       new Thread(new Run1()).start();
        for (int i = 0; i < 10; i++) {
            try {
                TimeUnit.MICROSECONDS.sleep(1);
            } catch (Exception e) {
                e.getMessage();
            }
            // System.out.println("主线程线程"+t++);
        }

    }

    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            try {
                TimeUnit.MICROSECONDS.sleep(1);
            } catch (Exception e) {
                e.getMessage();
            }
            //    System.out.println("子线程"+t++);
        }
    }

    static class Run1 implements Runnable {

        @Override
        public void run() {
            System.out.println("hello Thread");
        }
    }

    static class Thread1 extends Thread {
        @Override
        public void run() {
            System.out.println("hello Run");
        }
    }
    static class MyCall implements Callable<String>{

        @Override
        public String call() throws Exception {
            System.out.println("call:thread");
            return "success";
        }
    }
}
